//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_getmagsandmuzzles.sqf"
#include "x_setup.sqf"

private ["_weap","_sto","_cfgw","_muzzles","_ret_mags","_ret_muzzles","_ret"];
PARAMS_1(_weap);
__TRACE_1("","_weap");
_sto = GV2(GVAR(muzzle_store),_weap);
__TRACE_1("","_sto");
if (!isNil "_sto") exitWith {_sto};

_cfgw = configFile/"CfgWeapons"/_weap;
_muzzles = getArray(_cfgw/"muzzles");
__TRACE_1("","_muzzles");
_ret_mags = [];
_ret_muzzles = [];
{
	_mar = if (_x != "this") then {
		getArray(_cfgw/_x/"magazines");
	} else {
		getArray(_cfgw/"magazines");
	};
	_muzf = if (_weap == "Throw" || {_weap == "Put"} || {_x == "this"}) then {_weap} else {_x};
	{
		_ret_mags set [count _ret_mags, toUpper _x];
		_ret_muzzles set [count _ret_muzzles, _muzf];
	} forEach _mar;
} forEach _muzzles;
__TRACE_1("","_ret_mags");
__TRACE_1("","_ret_muzzles");
_ret = [_ret_mags, _ret_muzzles];
GVAR(muzzle_store) setVariable [_weap, _ret];
_ret